package com.jiuyou.clientController.sampleRecord;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sampleRecord.domain.SampleRecord;
import com.ruoyi.sampleRecord.service.ISampleRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 领样记录Controller
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/client/sampleRecord")
public class ClientSampleRecordController extends BaseController
{
    @Autowired
    private ISampleRecordService sampleRecordService;

    /**
     * 查询领样记录列表
     */
    @GetMapping("/list")
    public  List<SampleRecord> list(SampleRecord sampleRecord)
    {
        return sampleRecordService.selectSampleRecordList(sampleRecord);
    }

    /**
     * 导出领样记录列表
     */
    @Log(title = "领样记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SampleRecord sampleRecord)
    {
        List<SampleRecord> list = sampleRecordService.selectSampleRecordList(sampleRecord);
        ExcelUtil<SampleRecord> util = new ExcelUtil<SampleRecord>(SampleRecord.class);
        return util.exportExcel(list, "领样记录数据");
    }

    /**
     * 获取领样记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sampleRecordService.selectSampleRecordById(id));
    }

    /**
     * 新增领样记录
     */
    @Log(title = "领样记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SampleRecord sampleRecord)
    {
        return toAjax(sampleRecordService.insertSampleRecord(sampleRecord));
    }

    /**
     * 修改领样记录
     */
    @Log(title = "领样记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SampleRecord sampleRecord)
    {
        sampleRecord.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(sampleRecordService.updateSampleRecord(sampleRecord));
    }

    /**
     * 删除领样记录
     */
    @Log(title = "领样记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sampleRecordService.logicDeleteSampleRecord(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
